package com.fingard.util;

import java.util.Map;

/**
 * HTML拼接工具类
 *
 * @author cruise
 */
public class HtmlStitchUtil {
    public static String joinTR(Map<String, String> p_reqMap) {
        StringBuilder sbBuilder = new StringBuilder();

        for (String key : p_reqMap.keySet()) {
            sbBuilder.append("<tr><td><input type=\"hidden\" name=\"" + key + "\" value=\"" + p_reqMap.get(key) + "\"/></td></tr>");
        }

        return sbBuilder.toString();
    }

    /**
     * 通联收银宝网关支付表单内容
     */
    public static String joinTRForSYBGW02(Map<String, String> p_reqMap) {
        StringBuilder sbBuilder = new StringBuilder();

        for (String key : p_reqMap.keySet()) {
//            if (key.equals("goodsid") || key.equals("goodsinf") || key.equals("trxamt") || key.equals("orderid")) {
                sbBuilder.append("<tr>");
                sbBuilder.append("<td width=\"20%\" align=\"left\">" + p_reqMap.get(key).split("\\|")[1] + "</td>");
                sbBuilder.append("<td width=\"55%\" align=\"left\"><input size=\"70\" type=\"text\" name=\"" + key + "\" id=\"" + key + "\" value=\"" + p_reqMap.get(key).split("\\|")[0] + "\" /></td>");
                sbBuilder.append("</tr>");
//            } else {
//                sbBuilder.append("<tr>");
//                sbBuilder.append("<td width=\"20%\" align=\"left\">" + p_reqMap.get(key).split("\\|")[1] + "</td>");
//                sbBuilder.append("<td width=\"55%\" align=\"left\"><input size=\"70\" type=\"hidden\" name=\"" + key + "\" id=\"" + key + "\" value=\"" + p_reqMap.get(key).split("\\|")[0] + "\" /></td>");
//                sbBuilder.append("</tr>");
//            }

        }

        return sbBuilder.toString();
    }

    public static String buildHtml(String p_reqStr, String p_reqURL) {
        StringBuilder sbBuilder = new StringBuilder();

        sbBuilder.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
        sbBuilder.append("<HTML>");
        sbBuilder.append("  <HEAD><TITLE>A Servlet</TITLE>");
        sbBuilder.append("    <script type=\"text/javascript\">");
        sbBuilder.append("  		window.onload = function(){");
        sbBuilder.append("  			document.getElementById(\"orderform\").submit();");
        sbBuilder.append("  		}");
        sbBuilder.append("    </script>");
        sbBuilder.append("  </HEAD>");
        sbBuilder.append("  <BODY>");
        sbBuilder.append("<form id=\"orderform\" action=\"" + p_reqURL + "\" method=\"post\">");
        sbBuilder.append("<table>");
        sbBuilder.append(p_reqStr);
        sbBuilder.append("</table>");
        sbBuilder.append("</form>");
        sbBuilder.append("  </BODY>");
        sbBuilder.append("</HTML>");

        return sbBuilder.toString();
    }

    /**
     * 通联收银宝网关支付html
     */
    public static String buildHtmlForSYBGW02(String p_reqStr, String p_reqURL) {
        StringBuilder sbBuilder = new StringBuilder();

        sbBuilder.append("<!DOCTYPE html>");
        sbBuilder.append("<html>");
        sbBuilder.append("<head>");
        sbBuilder.append("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />");
        sbBuilder.append("<title>网银支付接口</title>");
        sbBuilder.append("</head>");
        sbBuilder.append("<body>");
        sbBuilder.append("<br /> <br />");
        sbBuilder.append("<table width=\"60%\" border=\"0\" align=\"center\" cellpadding=\"10\" cellspacing=\"0\" style=\"border:solid 1px #bababa\">");
        sbBuilder.append("<tr>");
        sbBuilder.append("<th align=\"center\" height=\"30\" colspan=\"2\" bgcolor=\"#5cacee\">请输入订单支付参数</th>");
        sbBuilder.append("</tr>");
        sbBuilder.append("<form method=\"post\" action=\"" + p_reqURL + "\" accept-charset=\"utf-8\">");
        sbBuilder.append(p_reqStr);
        sbBuilder.append("<tr>");
        sbBuilder.append("<td width=\"20%\" align=\"left\"></td>");
        sbBuilder.append("<td width=\"55%\" align=\"left\">");
        sbBuilder.append("<input type=\"submit\" value=\"提交订单\" />");
        sbBuilder.append("</td>");
        sbBuilder.append("</tr>");
        sbBuilder.append("</form>");
        sbBuilder.append("</table>");
        sbBuilder.append("</body>");
        sbBuilder.append("</html>");

        return sbBuilder.toString();
    }
}
